<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script type="text/javascript">
		
		window.onload = function(){

			var oDiv = document.getElementById('div1');
			var iLeft = 0;
			var iSpeed = 3;

			var timer = setInterval(function(){
				iLeft += iSpeed;
				oDiv.style.left = iLeft + 'px';

				if(iLeft>800){
					iSpeed = -3;
				}

				if(iLeft<0){
					iSpeed = 3;
				}				
			},30);

		}
	</script>
	<style type="text/css">
		.box{
			width:200px;
			height:200px;
			background-color: pink;
			position:absolute;
			left:0;
		}
	</style>
</head>
<body>
	<div class="box" id="div1"></div>
</body>
</html>